<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Students';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="student-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('添加', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'name',
            'age',
            [
                    'attribute'=>'sex',
                'value'=>function($dataProvider){
                    return $dataProvider->sex == 1 ? '男' : '女';
                }
            ],
            'phone',
//            'create_tm:date',
//            'update_tm:date',
            [
                'attribute'=>'create_tm',
                'value'=>function($dataProvider){
                    return $dataProvider->create_tm = date('Y-m-d H:i:s',$dataProvider->create_tm);
                }
            ],
            [
                'attribute'=>'update_tm',
                'value'=>function($dataProvider){
                    return $dataProvider->update_tm = date('Y-m-d H:i:s',$dataProvider->update_tm);
                }
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
